<template>
    <div class="container-content">
        <el-form
            ref="elForm"
            :model="formData"
            :rules="rules"
            size="medium"
            label-width="100px"
        >
            <el-form-item
                label-width="200px"
                label="再订货点"
                prop="againBuyNum"
            >
                <el-input
                    v-model="formData.againBuyNum"
                    placeholder="请输入再订货点"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item label-width="200px" label="物料" prop="materialId">
                <el-input
                    v-model="formData.materialId"
                    placeholder="请输入物料"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="数据状态"
                prop="dataStatus"
            >
                <el-select
                    v-model="formData.dataStatus"
                    placeholder="请选择数据状态"
                    clearable
                    :style="{ width: '100%' }"
                >
                    <el-option
                        v-for="(item, index) in dataStatusOptions"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="是否禁用"
                prop="isDisabled"
            >
                <el-select
                    v-model="formData.isDisabled"
                    placeholder="请选择是否禁用"
                    clearable
                    :style="{ width: '100%' }"
                >
                    <el-option
                        v-for="(item, index) in isDisabledOptions"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="最大库存数量"
                prop="maxStockNum"
            >
                <el-input
                    v-model="formData.maxStockNum"
                    placeholder="请输入最大库存数量"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="最小订购量"
                prop="minBuyNum"
            >
                <el-input
                    v-model="formData.minBuyNum"
                    placeholder="请输入最小订购量"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="最小包装量"
                prop="minPackNum"
            >
                <el-input
                    v-model="formData.minPackNum"
                    placeholder="请输入最小包装量"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="安全库存量"
                prop="safetyStockNum"
            >
                <el-input
                    v-model="formData.safetyStockNum"
                    placeholder="请输入安全库存量"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item label-width="200px" label="计量单位" prop="unit">
                <el-input
                    v-model="formData.unit"
                    placeholder="请输入计量单位"
                    clearable
                    :style="{ width: '100%' }"
                ></el-input>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import { add } from "@/api/base/data";
import { updataKingBaseSafetyStockList,editKingBaseSafetyStockList } from "@/api/bim/outher";
export default {
    components: {},
    props: ["id"],
    data() {
        return {
            flag:false,
            formData: {
                againBuyNum: undefined,
                materialId: undefined,
                dataStatus: undefined,
                isDisabled: undefined,
                maxStockNum: undefined,
                minBuyNum: undefined,
                minPackNum: undefined,
                safetyStockNum: undefined,
                unit: undefined,
            },
            rules: {
                againBuyNum: [
                    {
                        required: true,
                        message: "请输入再订货点",
                        trigger: "blur",
                    },
                ],
                materialId: [
                    {
                        required: true,
                        message: "请输入物料",
                        trigger: "blur",
                    },
                ],
                dataStatus: [
                    {
                        required: true,
                        message: "请选择数据状态",
                        trigger: "change",
                    },
                ],
                isDisabled: [
                    {
                        required: true,
                        message: "请选择是否禁用",
                        trigger: "change",
                    },
                ],
                maxStockNum: [
                    {
                        required: true,
                        message: "请输入最大库存数量",
                        trigger: "blur",
                    },
                ],
                minBuyNum: [
                    {
                        required: true,
                        message: "请输入最小订购量",
                        trigger: "blur",
                    },
                ],
                minPackNum: [
                    {
                        required: true,
                        message: "请输入最小包装量",
                        trigger: "blur",
                    },
                ],
                safetyStockNum: [
                    {
                        required: true,
                        message: "请输入安全库存量",
                        trigger: "blur",
                    },
                ],
                unit: [
                    {
                        required: true,
                        message: "请输入计量单位",
                        trigger: "blur",
                    },
                ],
            },
            dataStatusOptions: [
                {
                    label: "创建",
                    value: 1,
                },
                {
                    label: "审核中",
                    value: 2,
                },
                {
                    label: "已审核",
                    value: 3,
                },
            ],
            isDisabledOptions: [
                {
                    label: "是",
                    value: 1,
                },
                {
                    label: "否",
                    value: 2,
                },
            ],
        };
    },
    computed: {},
    watch: {},
    created() {},
    mounted() {
        if (this.id!='') {
            updataKingBaseSafetyStockList(this.id).then((res)=>{
                this.formData=res.data
                this.flag=true
            })
        }
    },
    methods: {
        submitForm(cb) {
            if (this.flag) {
                this.$refs["elForm"].validate((valid) => {
                if (!valid) return;
                // TODO 提交表单
                editKingBaseSafetyStockList(this.formData, "KingBaseSafetyStock").then((res) => {
                    if (res.code === 200) {
                        cb();
                        this.$message.success("修改成功");
                        this.flag=false
                    }
                });
            });
            }else{
                this.$refs["elForm"].validate((valid) => {
                if (!valid) return;
                // TODO 提交表单
                add(this.formData, "KingBaseSafetyStock").then((res) => {
                    if (res.code === 200) {
                        cb();
                        this.$message.success("新增成功");
                    }
                });
            });
            }
        },
        resetForm() {
            this.$refs["elForm"].resetFields();
        },
    },
};
</script>
<style></style>
